
<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
${aier_doctype}
<html <s:property value="aier_html_xmlns" escape="false"/>>
<head>
<meta http-equiv="Content-Type" content="${aier_content_type}" />
<meta name="keywords" content="${aier_keyworks}" />
<meta name="description" content="${aier_description}" />
<title>${aier_title}</title>
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}ui.css" />
<link rel="Stylesheet" href="${aier_css_url}jq/jq.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/jq-msg.css" />

<link rel="stylesheet" href="${aier_css_url}social/module/reset.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/btn.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/icon.css" />
<link rel="Stylesheet" href="${aier_css_url}social/module/emotion.css" />
<link rel="Stylesheet" href="${aier_css_url}social/module/homeside.css" />
<link rel="stylesheet" href="${aier_css_url}social/user/userMessage/usermessage.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/xxs.css" />

<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}${aier_jqui_js}ui.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/msg.js"></script>
<script type="text/javascript" src="${aier_js_url}97/WdatePicker.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/cn.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/block.js"></script>
<script type="text/javascript"
	src="${aier_js_url}emotion/xxsemotion.2.js"></script>
<script type="text/javascript" src="${aier_js_url}trantime/jquery-aier.js"></script>

</head>
<body>

	<!-- 顶栏 -->
	<s:action name="userhomecomm_homeHead" namespace="/user" executeResult="true"></s:action>
	<!-- 顶栏结束 -->


	<div class="window-content">

		<!-- wrap  -->
		
		<div class="wrap wrap-msg wrap-message wrap-tri-col clearfix" style="_width:1000px;">
			<!-- 主侧栏 -->
			<s:action name="usermessage_msgSide" namespace="/user" executeResult="true"></s:action>


			<!-- 主区域 (右  -->
			<div class="wrap-main clearfix">
				<div class="msg-stream msg-comment">
					<div class="msg-title title">
						<div class="group">
							<a class="current" id = "tagReceive">收到的评论</a>
							<span>|</span>
							<a id = "tagSend">发出的评论</a>
						</div>
					</div>
                    <!-- 收到的评论 -->
                    <div id="msgReceiveComment">
                    
	                </div>


                    <!-- 发出的评论 -->
                    <div id="msgSendComment" style="display:none;">
                    
	
	                </div>
	                <!-- /发出的评论 -->

		            <div id="deleteConfirm" style="display: none;" title="删除">
		                <p>确认要删除此评论吗?</p>
		            </div>
            
                    <div id = "page"></div>
				</div>

				<!-- 右栏 -->
                <s:action name="userhomecomm_homeRight" namespace="/user" executeResult="true"></s:action>
				
			</div>

			<!-- 返回顶部 -->
			<s:action name="userhomecomm_backToTop" namespace="/user" executeResult="true"></s:action>
			<!-- end 返回顶部 -->


		</div>
		<!-- footer copyright -->
		<s:action name="userhomecomm_homeFooter" namespace="/user" executeResult="true"></s:action>
		<!-- /footer copyright -->
	</div>



<script type="text/javascript">
	$('.menubtn').click(function(){
		$(this).next('.menu').toggle();
	});

// 转换时间
$(document).ready(function(){
	$('.msg-date').each(function(){
		$(this).tranTime();
	});
});
// 预览图和完整图切换
$('.zoom-out').click(function(){
	$(this).parents('.xxs-extend').css('display','none')
	.prev('.xxs-media-pre').css('display','block');
});
$('.zoom-in').click(function(){
	$(this).parents('.xxs-media-pre').css('display','none')
	.next('.xxs-extend').css('display','block');
});
// 收到的评论 和 发出的评论 切换
$('#tagReceive').click(function(){
    if (!$(this).hasClass('current')) {
        $('#tagSend').removeClass('current');
        $('#msgSendComment').hide();
        $(this).addClass('current');
        $('#msgReceiveComment').show();
        searchReceive(rpage);
    }
});
$('#tagSend').click(function(){
    if (!$(this).hasClass('current')) {
        $('#tagReceive').removeClass('current');
        $('#msgReceiveComment').hide();
        $(this).addClass('current');
        $('#msgSendComment').show();
        searchSend(spage);
    }
});

$(window).bind('scroll', function(){
	var a = $(this).scrollTop(),
		b = $(this).outerHeight();
	if ( a > 100 ) {
		$('#btt').css({'display':'block','top':a+b-200});
	} else {
		$('#btt').css('display','none');
	}
});

$('#btt').click(function(){
	$('body').scrollTop(0);
});

function openCCClick(){
    // 插入表情 - 发表对评论的回复
    $('.cc-submit-bar>.btn-emotion').click(function(){
        
        $(this).sinaEmotion({
            emotionUrl: '${aier_js_url}trantime/emotions.js',
            target : $(this).closest('.input-box').find('textarea')
        });
	});
}

                                      
</script>

<script type="text/javascript">
var rpage = 1;      // 收到的评论的当前页
var spage = 1;      // 发出的评论的当前页
var page_size = 10; // 每页的记录数

    $(document).ready(function() {
      
        // 获取关注分组
        var fun=function(data){
            if(data.s==1){
                var c = "";
                for (var i=0;i<data.fgList.length;i++) {
                    if (data.fgList[i].name == "特别关注") {
                        c += "<div class='tab-normal'><a class='btn' href='${aier_url}user/userhomeforums_homeForums.shtml?fgid="+data.fgList[i].fgid+"'><em class='icon-1 icon-1-teguan'></em><span>"+data.fgList[i].name+"</span></a></div>";
                    } else {
                        c += "<div class='tab-normal'><a class='btn' href='${aier_url}user/userhomeforums_homeForums.shtml?fgid="+data.fgList[i].fgid+"'><em class='icon-1 icon-1-weifen'></em><span>"+data.fgList[i].name+"</span></a></div>";
                    }
                    
                }
                $("#group").html(c);
                
            }
        };
        exeAjax(
             ajaxUrl("${aier_url}${aier_urijs}usermyfollow_searchFollowGroup${aier_suffix}"),
             fun,{
        });
        searchReceive(rpage);
    });
    
    // 获取收到的评论
    function searchReceive(nowrpage) {
    	rpage = nowrpage;
        var fun=function(data){
            if(data.s==1){
                var html = "";
                if (data.fcList == null || data.fcList.length == 0) {
                    html += '<div class="msg-number">暂时没有收到评论</div>';
                } else {
                    html += '<div class="msg-number">共'+data.count+'条</div>';
                    html += '<div class="msg-receive-comment-list clearfix">';
                    for (var i=0;i<data.fcList.length;i++) {
	                    var fc = data.fcList[i];
	                    html += '<div class="msg-receive-comment-item" data-xxfcuid="'+fc.fcuid+'" data-fid="'+fc.fid+'"><div class="avatar"><a href="${aier_url}user/uccomm_userCenter.shtml?in_uid='+fc.fcuid+'"><img src="${get_picturl_url}small/'+fc.headimg+'" alt=""></a></div>';
	                    html += '<div class="detail"><div class="content"><a class="username">'+fc.nickname+'</a><span class="content-text">'+fc.content+'</span></div>';
	                    if (fc.type == 1) {
	                       // 评论
	                       html += '<div class="related-xxs"><span>评论我的微博</span>';
	                    } else {
	                       // 回复
	                       html += '<div class="related-xxs"><span>回复我的评论</span>';
	                    }
	                    if (!isnull(fc.rcontent)) {
	                    	html += ':<a class="text">'+fc.rcontent+'</a>';
	                    }
	                    html += '</div><div class="function clearfix"><div class="left">'+fc.cdate.split("T")[0]+" "+fc.cdate.split("T")[1]+'</div>';
	                    html += '<div class="right"><a class="delete" onclick="deleteComment('+fc.fcid+',1);" >删除</a><span>|</span><a class="reply">回复</a></div></div>';
	                    html += '<div class="comment" style="display:none;"><div class="input-box"><div class="textarea-bar"><textarea name="" id="" class="comment-textarea" data-id="123"></textarea></div>';
	                    html += '<div class="submit-bar clearfix"><div class="cc-submit-bar"><a class="btn-emotion icon-1 icon-1-emotion"></a></div><div class="right-submit"><a class="btn-orange-2"><span>评论</span></a></div>';
	                    html += '</div></div></div></div></div>';
	                }
	                html += '</div>';
                }
                
                $("#msgReceiveComment").html(html);
                // $("#msgReceiveComment .text").each(function(){
                // 	$(this).tranText({
                // 		emotionUrl: '${aier_js_url}trantime/emotions.js'
                // 	});
                // });
                // $("#msgReceiveComment .content-text").each(function(){
                //     $(this).tranText({
                //     	emotionUrl: '${aier_js_url}trantime/emotions.js'
                //     });
                // });
                openCCClick();
                
                // 对评论的回复(动画)
                 $('.reply').click(function(){
				     //var thisid = $(this).closest('.msg-receive-comment-item').attr('data-maciid');
				     var thisname = $(this).closest('.msg-receive-comment-item').find('.username').text();
				     var targetComment = $(this).closest('.function').next('.comment');
				     var targetArea = $(this).closest('.function').next('.comment').find('textarea');
				     targetComment.toggle();
				     targetArea.focus();
				     targetArea.text('回复'+'@'+thisname+':');
				 });
				 
                // 回复
                $('.right-submit').click(function() {
                     var content = $(this).closest('.comment').find('textarea').val();
                     var rcontent = $(this).closest('.msg-receive-comment-item').find('.content-text').html();
                     var fid = $(this).closest('.msg-receive-comment-item').attr('data-fid');
                     var rfcuid = $(this).closest('.msg-receive-comment-item').attr('data-xxfcuid');
                     
                     if (content.substring(content.indexOf(":")+1).length == 0) {
                         $().message("回复内容不能为空！");
                         return;
                     }
                     if (content.length > 200) {
                        $().message("回复内容太长！");
                        return;
                     }
                     
                     var thisobject = $(this);
                     var fun=function(data){
                       if(data.s==1){
                           thisobject.closest('.comment').find('textarea').val(content.substring(0,content.indexOf(":")+1));
                           $().message("回复成功！");
                       } else {
                           $().message("回复失败，请稍后再试！");
                       }
                   };
                   exeAjax(
                        ajaxUrl("${aier_url}${aier_urijs}userhomeforums_commentFresh${aier_suffix}"),
                        fun,{
                        	"fid":fid,
                            "rfcuid":rfcuid,
                            "content":content,
                            "rcontent":rcontent,
                            "ctype":2,
                            "flag":0
                   });
                });
                // 更新分页显示
                rpage = data.page;
                toLoadPage(rpage, page_size, data.page_count, data.count, "page", "searchReceive", null, null);  
                if (data.count == 0) {
                    $("#page").css("display","none");
                } else {
                    $("#page").css("display","block");
                }
            }
        };
        exeAjax(
             ajaxUrl("${aier_url}${aier_urijs}usermessage_searchReceiveComment${aier_suffix}"),
             fun,{
             "page":rpage,
             "page_size":page_size
        });
    }
    
    // 获取发出的评论   
    function searchSend(nowspage) {
    	spage = nowspage;
        var fun=function(data){
            if(data.s==1){
                var html = "";
                if (data.fcList == null || data.fcList.length == 0) {
                    html += '<div class="msg-number">暂时没有评论</div>';
                } else {
                    html += '<div class="msg-number">共'+data.count+'条</div>';
                    html += '<div class="msg-send-comment-list clearfix">';
                    for (var i=0;i<data.fcList.length;i++) {
                        var fc = data.fcList[i];
                        html += '<div class="msg-send-comment-item"><div class="avatar"><a href=""><img src="${get_picturl_url}small/'+data.userInfo.headimg+'" alt=""></a></div>';
                        html += '<div class="detail"><div class="content"><span class="content-text">'+fc.content+'</span></div>';
                        if (fc.type == 1) {
                           // 评论
                           html += '<div class="related-xxs"><span>评论 <a class="text">'+fc.nickname+'</a> 的微博</span>';
                        } else {
                           // 回复
                           html += '<div class="related-xxs"><span>回复 <a class="text">'+fc.nickname+'</a> 的评论</span>';
                        }
                        if (!isnull(fc.rcontent)) {
                            html += ':<a class="text">'+fc.rcontent+'</a>';
                        }
                        html += '</div><div class="function clearfix"><div class="left">'+fc.cdate.split("T")[0]+" "+fc.cdate.split("T")[1]+'</div>';
                        html += '<div class="right"><a class="delete" onclick="deleteComment('+fc.fcid+',2);" >删除</a></div></div>';
                        html += '</div></div>';
                    }
                    html += '</div>';
                }
                
                $("#msgSendComment").html(html);

                // $("#msgSendComment .text").each(function(){
                //     $(this).tranText({
                //     	emotionUrl: '${aier_js_url}trantime/emotions.js'
                //     });
                // });
                // $("#msgSendComment .content-text").each(function(){
                //     $(this).tranText({
                //     	emotionUrl: '${aier_js_url}trantime/emotions.js'
                //     });
                // });
                
                // 更新分页显示
                spage = data.page;
                toLoadPage(spage, page_size, data.page_count, data.count, "page", "searchSend", null, null); 
                if (data.count == 0) {
                    $("#page").css("display","none");
                } else {
                    $("#page").css("display","block");
                }
            }
        };
        exeAjax(
             ajaxUrl("${aier_url}${aier_urijs}usermessage_searchSendComment${aier_suffix}"),
             fun,{
             "page":spage,
             "page_size":page_size
        });
    }
    
    // 删除评论    
    function deleteComment(fcid,type) {
        $(function() {
            $("#deleteConfirm").dialog(
                {
                    //背景变暗
                    modal : true,
                    autoOpen : false,
                    show : "fade",
                    hide : "fade",
                    width : "340",
                    height : "220",
                    buttons : {
                        "确定" : function() {
                            
                            var fun=function(data){
                                if(data.s==1){
                                    $("#deleteConfirm").dialog("close");
                                    if (type == 1) {
                                        searchReceive(rpage);
                                    } else {
                                        searchSend(spage);
                                    }
                                }
                                
                            };
                            exeAjax(
                                 ajaxUrl("${aier_url}${aier_urijs}userhomeforums_deleteComment${aier_suffix}"),
                                 fun,{
                                    "fcid":fcid
                            });
                                            },
                        "取消" : function() {
                            $(this).dialog("close");
                        }
                }
            });
            $("#deleteConfirm").dialog("open");
        });
        
    }
    
    // 跳转到家校联系薄
    function hsConBook() {
        // 判断是否付费

        // 判断身份（家长或老师）

        // 教师（tid）
        //window.location.href = "${aier_url}user/userhscb_userTeaHSConBook.shtml?tid=2&&cid=1";
        var fun = function(data) {
            if (data.s == 1) {

                if (data.type == 0) {
                    $().message("您目前没有权利进入家校联系薄！");
                    return;
                } else if (data.type == 1 || data.type == 3) {
                    if (data.classList != null && data.classList.length > 0) {
                        window.location.href = "${aier_url}user/userhscb_userTeaHSConBook.shtml?cid="
                                + data.classList[0].cid +"&type="+data.type;
                    } else {
                        window.location.href = "${aier_url}user/userhscb_userTeaHSConBook.shtml?type="+data.type;
                    }

                } else if (data.type == 2) {
                    window.location.href = "${aier_url}user/userhscb_userChiHSConBook.shtml?type="+data.type;
                }

            }
        };
        exeAjax(
                ajaxUrl("${aier_url}${aier_urijs}userhscb_searchClassList${aier_suffix}"),
                fun, {});

    }
    
</script>

</body>
</html>